package yz.hdfs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.net.URI;

public class demo5DeleteFile {
    public static void main(String[] args) throws Exception{
        Configuration entries = new Configuration();
        FileSystem fileSystem = FileSystem.get(new URI("hdfs://master:9001"), entries,"root");

        //第二个参数表示是否迭代删除，就是子目录下有时还会删除
        //fileSystem.delete(new Path("/out"),true);

        //但是还是要判断一下文件是否存在‘
        Path path = new Path("/out");
        if (fileSystem.exists(path)){
            fileSystem.delete(path,true);
        }

    }

}
